Page({
  data: {
    canIUse: true,
    logo: "",
    username: ""
  },
  onLoad: function () {
    console.log(this.data);
    // 查看是否授权
    var self = this
    wx.getSetting({
      success(res) {
        if (res.authSetting['scope.userInfo']) {
          // 已经授权，可以直接调用 getUserInfo 获取头像昵称
          wx.getUserInfo({
            success: (res) => {
              console.log(res)
              self.setData({
                canIUse: false,
                logo: res.userInfo.avatarUrl,
                username: res.userInfo.nickName
              })
            }
          })
        }
      }
    })
  },
  bindGetUserInfo(e) {
    console.log(e.detail.userInfo);
    let userInfo = e.detail.userInfo
    if (userInfo) {
      var { nickName, avatarUrl } = userInfo
      this.setData({
        canIUse: false,
        logo: avatarUrl,
        username: nickName
      })
    }
  }
})